<template>
	<view class="container">
		<nav-bar :title="$t('消息列表')" leftIcon="left" ></nav-bar>
		 <!-- v-for="(item,i) in list" :key="i" -->
		<view class="typeList">
			<view :class="index == key?'moneyNameKk':'moneyNameKk2'" v-for="(item,key) in typeList" :key="key" @click="handleType(key)" style="color: #fff;">
				{{item.typeName}}
			</view>					
		</view>		
		 <view class="" style="margin-top: 120rpx;">
			<view class="listMain" v-for="(item,i) in list" :key="i">
				<view class="leftList">
					<view class="text">
						{{item.content}} 
					</view>
					<view class="time">
						{{$t('時間')}}：{{item.sentAt}}
					</view>
				</view>
			</view>		 	
		 </view>
	</view>
</template>

<script setup>
	import {
		ref
	} from "vue";
	import msgListData from '@/hooks/msgList.js'
	import i18n from '@/locale/index'
	import {
		onShow,
		onReachBottom
	} from '@dcloudio/uni-app'
	const {
		sumComputed,
		getXxList
	} = msgListData()

	const page = ref({
		pageNum: 1,
		pageSize: 10,
	})
	const index = ref(1)
	const typeList = ref([
		{
			index:0,
			typeName:i18n.global.t('個人')
		},{
			index:1,
			typeName:i18n.global.t('團隊')		
		}
	])
	//列表字段
	const list = ref([])
	const handleYd = async(e)=>{
		let list = {
			userId: uni.getStorageSync('setUserInfo').userId,
			languageType:uni.getStorageSync('lang') == 'en'?'en':'zh',
		}
		const data = await getXxList('message/messageEdit',list)
	}
	const handleType = (e)=>{
		list.value = []
		page.value.pageNum = 1
		index.value = e == 1?index.value = 1: index.value = 0
		getRechargeRecordList()
	}
	async function getRechargeRecordList() {
		const res = await getXxList('message/messageList', {
			userId: uni.getStorageSync('setUserInfo').userId,
			pageNum: page.value.pageNum,
			pageSize: page.value.pageSize,
			messagesType:index.value,
			languageType:uni.getStorageSync('lang') == 'en'?'en':'zh',
		})
		if(res.total == 0){
			return uni.showToast({
				title: `${i18n.global.t('暫無數據')}!`,
				icon: 'none',
			})
		}else
		if (!res.records.length) {
			return uni.showToast({
				title: `${i18n.global.t('没有更多了')}!`,
				icon: 'none',
			})
		}else{
			list.value = [...list.value, ...res.records]
		}
		
	}
	onShow(async () => {
		// getRechargeRecordList()
		handleYd()
		handleType()
	})		
	
	//上拉加载更多
	onReachBottom(() => {
		page.value.pageNum++
		getRechargeRecordList()
		
	})
</script>

<style lang="scss" scoped>
	.moneyNameKk2{
		width: 180rpx;
		height: 60rpx;
		background: #b3b3b3;
		border-radius: 10rpx;
		text-align: center;
		line-height: 60rpx;
		margin-right: 25rpx;
	}
	.moneyNameKk {
		width: 180rpx;
		height: 60rpx;
		background: linear-gradient(90deg, #039BDA, #0DF2ED);
		border-radius: 10rpx;
		text-align: center;
		line-height: 60rpx;
		margin-right: 25rpx;
	}
	.typeList{
		display: flex;
		align-items: center;
		padding: 35rpx;
		position: fixed;
		top: 150rpx;
		background-color: rgb(24, 23, 30);
		width: 100%;
	}
	.listMainLine {
		padding: 25rpx 45rpx;
		background: #24232C;
		// border-radius: 20rpx;
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
		border: 1rpx solid #4b4b4b;
		margin-bottom: 15rpx;
		
	}
	.text {
		color: #FFFFFF;
		font-size: 28rpx;
		 word-break: break-all;
		white-space: normal;
		width: 690rpx;
	}
	.time {
		color: #808492;
		font-size: 24rpx;
		margin-top: 22rpx;
	}
	.listMain {
		padding: 25rpx 45rpx;
		background: #24232C;
		// border-radius: 20rpx;
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
		// border-bottom: 1rpx solid #4b4b4b;
		margin-bottom: 15rpx;

	}
</style>